package com.sgb.kjwl.view.ui.fragment.home;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.tabs.TabLayout;

import com.sgb.kjwl.AppFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentGoodsMainGoodsListBinding;
import com.sgb.kjwl.di.material.DaggerMaterialFragComponent;
import com.sgb.kjwl.di.material.MaterialFragModule;
import com.sgb.kjwl.model.entity.GoodsListTypeEntity;
import com.swgk.core.util.StringUtil;
import com.swgk.core.view.entity.MenuEntity;
import com.sgb.kjwl.model.entity.ProvinceEntity;
import com.sgb.kjwl.model.entity.request.MaterialFilterJson;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.model.entity.user.AreaChooseEntity;
import com.sgb.kjwl.model.entity.user.ConcreteEntity;
import com.sgb.kjwl.model.entity.user.GoodsListEntity;
import com.sgb.kjwl.model.entity.user.MaterChooseEntity;
import com.sgb.kjwl.model.entity.user.RecommendListEntity;
import com.sgb.kjwl.model.entity.user.TwoOrThreeLevelEntity;
import com.sgb.kjwl.utils.ActivityClassHelper;
import com.sgb.kjwl.utils.LocationUtil;
import com.sgb.kjwl.view.event.ChooseAreaEvent;
import com.swgk.core.event.EventConstant;
import com.sgb.link.event.LeaseEvent;
import com.sgb.link.event.MaterialEvent;
import com.sgb.alimaplibrary.SelectAddressActivity;
import com.sgb.kjwl.view.ui.activity.home.HomeCategoryActivity;
import com.sgb.kjwl.view.ui.activity.material.ConcreteDetailActivity2;
import com.sgb.kjwl.view.ui.activity.material.GoodsAggregateActivity;
import com.sgb.kjwl.view.ui.activity.self.shop.ShopGoodsDetailActivity;
import com.sgb.kjwl.view.ui.adapter.search.MaterialAdapter;
import com.sgb.kjwl.view.ui.adapter.search.MatterChooseAdapter;
import com.sgb.kjwl.view.ui.adapter.search.RecommendGoodsAdapter;
import com.sgb.kjwl.view.ui.adapter.search.RecommendMatterChooseAdapter;
import com.sgb.kjwl.view.widget.DictWindow5;
import com.sgb.kjwl.view.widget.MatterChooseMaterialFliterPopWindow3;
import com.sgb.kjwl.view.widget.ThreeLevelAreaWindow;
import com.sgb.kjwl.view.widget.transport.MatterChooseWindow;
import com.sgb.kjwl.viewmodel.home.GoodsMainGoodsListModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.base.model.entity.RequestCode;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.recyclerview.entity.BaseAreaEntity;
import com.swgk.core.util.ResolutionUtil;
import com.swgk.core.xrecyclerview.AppBarStateChangeListener;
import com.swgk.core.xrecyclerview.XRecyclerView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import javax.inject.Inject;

/***
 * 首页模块商品界面的商品展示界面
 * @author Administrator
 * 说明：2021.07.19 已弃用 使用GoodsMainGoodsListFragment3代替
 */
@Deprecated
public class GoodsMainGoodsListFragment extends AppFragment {

    @Inject
    GoodsMainGoodsListModel mModel;
    private FragmentGoodsMainGoodsListBinding mBinding;
    private String mLon = "0";
    private String mLat = "0";
    private MatterChooseMaterialFliterPopWindow3 mPopWindow;
    private DictWindow5 distanceWindow5;
    private String distanceId = "";
    private List<MenuEntity> mGoodsType;
    private int mPageNum = 1;
    private String mDistance = "";
    private String mPriceSort = "0";
    private String mCid1 = "";
    private String mCid3 = "";
    private String mCategoryId = "";
    private List<String> mBrandId = new ArrayList<>();
    private List<String> mMaterValue = new ArrayList<>();
    private boolean isLoadMoreGoodsList;
    private boolean isLoadMoreRecommendGoodsList;
    private MaterialAdapter mMaterialAdapter;
    private List<String> mAreaId = new ArrayList<>();
    private String mCityId = "";
    private String mProvince = "";
    private int mRecommendPageNum = 0;
    private String mRecommendValId = "";
    private String mItemCid1 = "";
    private String mItemCid2 = "";
    private String mItemCid3 = "";
    private RecommendGoodsAdapter mRecommendGoodsAdapter;
    private ThreeLevelAreaWindow mThreeLevelPopWindow;
    private MatterChooseAdapter mMatterChooseAdapter;
    private RecommendMatterChooseAdapter mRecommendMatterChooseAdapter;
    private int mSelectType = 0;
    private int mSelectTab = 0;
    private List<TwoOrThreeLevelEntity> mTwo;
    private List<TwoOrThreeLevelEntity> mThree;
    private List<DictEntity3> mDistanceData;
    private String mArea = "";
    private String mDistanceName = "";
    private String mOneType, mTwoType = "", mThreeType = "";
    private String mPosition;
    private Map<String, MaterChooseEntity.TypeBean> mRecommendStr = new HashMap<>();
    private Map<String, MaterChooseEntity.TypeBean> mStr = new HashMap<>();
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> mAreaList = new ArrayList<>();
    private String mIndustry;
    private MaterialHomeFragment materialHomeFragment;
    private StringBuilder sbl;
    private boolean mIsFirst = true;
    private int whereJump;

    private AppBarLayout.LayoutParams layoutParams;
    private boolean isAppBarExpended = false;
    private static final String TGA = "GoodsMainGoodsListFragment";
    private boolean isParentAppBarCollapsed = false;

    private boolean isUpDragging = true;
    private final static int FLAG_NO_SCROLL = AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL;
    private final static int FLAG_SCROLL_AND_ENTER_ALWAYS = AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL + AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS;

    /***
     * 0是推荐商品 1是全部商品
     */
    private int type;
    /***
     * 推荐商品
     *true 自营商品 false 非自营
     */
    private boolean selfEmployedGoods;
    /***
     * 是否是自营产品
     */
    private boolean isZiYingChecked = false;
    /***
     * 推荐商品
     * true 促销商品 false 非促销商品
     */
    private boolean isPromotionalGoods;

    /***
     * 推荐商品
     * true 选中促销商品tab false 非选中促销商品
     */
    private boolean isPromotionChecked = false;

    /***
     * 是否与地区关联
     */
    private boolean isRegionalConnection;

    /***
     * 推荐商品
     * 是否是热销产品
     */
    private boolean isSellGoodGoodsChecked;
    /***
     *
     */
    private int industryPosition;
    /****
     * 是否重置定位
     */
    private boolean isRePositioning;

    private boolean isStartAct1 = true;//第2层的定位标识
    private boolean isStartAct2 = true;//弟3层的定位标识

    @Override
    protected void setupFragmentComponent(AppComponent appComponent) {
        DaggerMaterialFragComponent.builder()
                .appComponent(appComponent)
                .materialFragModule(new MaterialFragModule(this))
                .build()
                .inject(this);
    }

    public static GoodsMainGoodsListFragment newInstance(int type, List<MenuEntity> goodsType, String position, int whereJump, boolean selfEmployedGoods, boolean isRegionalConnection) {
        GoodsMainGoodsListFragment goodsMainGoodsListFragment = new GoodsMainGoodsListFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("goodsListType", type);
        bundle.putInt("whereJump", whereJump);
        bundle.putSerializable("goodsList", (Serializable) goodsType);
        bundle.putString("childPosition", position);
        bundle.putBoolean("selfEmployedGoods", selfEmployedGoods);
        bundle.putBoolean("isRegionalConnection", isRegionalConnection);
        goodsMainGoodsListFragment.setArguments(bundle);
        return goodsMainGoodsListFragment;
    }

    public static GoodsMainGoodsListFragment newInstance(int type, List<MenuEntity> goodsType, String position, String industry, String obligate, boolean selfEmployedGoods, boolean promotionalGoods, boolean isRegionalConnection) {
        GoodsMainGoodsListFragment goodsMainGoodsListFragment = new GoodsMainGoodsListFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("goodsListType", type);
        bundle.putSerializable("goodsList", (Serializable) goodsType);
        bundle.putString("childPosition", position);
        bundle.putString("industry", industry);
        bundle.putString("obligate", obligate);
        bundle.putBoolean("selfEmployedGoods", selfEmployedGoods);
        bundle.putBoolean("promotionalGoods", promotionalGoods);
        bundle.putBoolean("isRegionalConnection", isRegionalConnection);
        goodsMainGoodsListFragment.setArguments(bundle);
        return goodsMainGoodsListFragment;
    }

    @Deprecated
    public static GoodsMainGoodsListFragment newInstance(int type, List<MenuEntity> goodsType, String position, String province) {
        GoodsMainGoodsListFragment goodsMainGoodsListFragment = new GoodsMainGoodsListFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("goodsListType", type);
        bundle.putSerializable("goodsList", (Serializable) goodsType);
        bundle.putString("childPosition", position);
        bundle.putString("province", province);
        goodsMainGoodsListFragment.setArguments(bundle);
        return goodsMainGoodsListFragment;
    }

    public static GoodsMainGoodsListFragment newInstance(int type, List<MenuEntity> goodsType, String id, String mOne, String mTwo, String mThree,
                                                         boolean selfEmployedGoods, boolean isRegionalConnection) {
        GoodsMainGoodsListFragment goodsMainGoodsListFragment = new GoodsMainGoodsListFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("goodsListType", type);
        bundle.putSerializable("goodsList", (Serializable) goodsType);
        bundle.putString("childPosition", id);
        bundle.putString("one", mOne);
        bundle.putString("two", mTwo);
        bundle.putString("three", mThree);
        bundle.putBoolean("selfEmployedGoods", selfEmployedGoods);
        bundle.putBoolean("isRegionalConnection", isRegionalConnection);
        goodsMainGoodsListFragment.setArguments(bundle);
        return goodsMainGoodsListFragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_goods_main_goods_list, container, false);
        return mBinding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
    }

    private void initView() {
        assert getArguments() != null;
        type = getArguments().getInt("goodsListType");
        whereJump = getArguments().getInt("whereJump", 0);
        mGoodsType = (List<MenuEntity>) getArguments().getSerializable("goodsList");
        mPosition = getArguments().getString("childPosition");
        mOneType = getArguments().getString("one");
        mTwoType = getArguments().getString("two");
        mThreeType = getArguments().getString("three");
        mProvince = getArguments().getString("province");
        mIndustry = getArguments().getString("industry");
        selfEmployedGoods = getArguments().getBoolean("selfEmployedGoods", false);
        isPromotionalGoods = getArguments().getBoolean("promotionalGoods", false);
        isRegionalConnection = getArguments().getBoolean("isRegionalConnection", false);
        if (mProvince == null) {
            mProvince = "";
        }
        if (selfEmployedGoods) {
            mBinding.llSelfEmployed.setVisibility(View.GONE);
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mBinding.llPromotionalGoods.getLayoutParams();
            layoutParams.setMargins(0, 0, ResolutionUtil.dp2px(Objects.requireNonNull(Objects.requireNonNull(requireContext())), 5), 0);
            mBinding.llPromotionalGoods.setLayoutParams(layoutParams);
        } else {
            mBinding.llSelfEmployed.setVisibility(View.VISIBLE);
            mBinding.llSelfEmployed.setOnClickListener(this::onMultiClick);
        }

        if (isPromotionalGoods) {
            mBinding.llPromotionalGoods.setVisibility(View.GONE);
            mBinding.llSellGoods.setVisibility(View.GONE);
        } else {
            mBinding.llPromotionalGoods.setVisibility(View.VISIBLE);
            mBinding.llPromotionalGoods.setOnClickListener(this::onMultiClick);
            mBinding.llSellGoods.setVisibility(View.VISIBLE);
            mBinding.llSellGoods.setOnClickListener(this::onMultiClick);
        }

        if (isRegionalConnection) {
            mProvince = mModel.getAreaCode();
        }
        mBinding.setGoodsFragment(this);
        GoodsListTypeEntity typeEntity = ActivityClassHelper.getGoodsListStyle(getContext(), type);
        mBinding.setGoodsType(typeEntity);
        AppBarLayout.LayoutParams lp = (AppBarLayout.LayoutParams) mBinding.rlGoodsMainGoodsListTab.getLayoutParams();
        lp.setMargins(0, 0, 0, 0);
        mBinding.rlGoodsMainGoodsListTab.setLayoutParams(lp);
        mBinding.rlGoodsMainGoodsListTab.setBackgroundResource(R.color.white);
//        if (type == 1) {
//            CoordinatorLayout.LayoutParams lp1 = (CoordinatorLayout.LayoutParams) mBinding.xrvFragmentGoodsMainGoodsList.getLayoutParams();
//            lp1.setMargins(0, ResolutionUtil.dp2px(getContext(), 10), 0, ResolutionUtil.dp2px(getContext(), 70));
//            mBinding.xrvFragmentGoodsMainGoodsList.setLayoutParams(lp1);
//        }
        mBinding.setGoodsModel(mModel);
        this.layoutParams = (AppBarLayout.LayoutParams) mBinding.rlGoodsMainGoodsListTab.getLayoutParams();
        this.layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
        mBinding.rlGoodsMainGoodsListTab.setLayoutParams(layoutParams);
        mBinding.tlFragmentGoodsMainGoodsSelectTitle2.setVisibility(View.GONE);
        mBinding.tlFragmentGoodsMainGoodsSelectTitle3.setVisibility(View.GONE);
        mBinding.ivFragmentGoodsMainGoodsTag2.setVisibility(View.GONE);
        mBinding.ivFragmentGoodsMainGoodsTag3.setVisibility(View.GONE);

        mBinding.tlFragmentGoodsMainGoodsSelectTitle1.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                setCurrentTab(tab);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        mBinding.tlFragmentGoodsMainGoodsSelectTitle2.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                if (tab.getPosition() == 0) {
                    mBinding.rlGoodMatterChoose.setVisibility(View.GONE);
                    mBinding.rvGoodMatterChoose.setVisibility(View.GONE);
                    if (type == 0) {
                        mItemCid2 = "";
                        mItemCid3 = "";
                        mRecommendValId = "";
                        mRecommendStr.clear();
                    } else {
                        mCid3 = "";
                        mCategoryId = "";
                        mMaterValue.clear();
                        mStr.clear();
                    }
                }

                String id;
                if (type == 0) {
                    mItemCid2 = mTwo.get(tab.getPosition()).getId();
                    id = mItemCid2;
                } else {
                    mCategoryId = mTwo.get(tab.getPosition()).getId();
                    id = mCategoryId;
                }
                if (tab.getPosition() == 0) {
                    mBinding.tlFragmentGoodsMainGoodsSelectTitle3.setVisibility(View.GONE);
                    mBinding.ivFragmentGoodsMainGoodsTag3.setVisibility(View.GONE);
                    if (type == 0) {
                        loadRecommendList(true);
                    } else {
                        whereJump = -1;
                        loadAllList(true);
                    }
                } else {
                    mBinding.tlFragmentGoodsMainGoodsSelectTitle3.setVisibility(View.VISIBLE);
                    mBinding.ivFragmentGoodsMainGoodsTag3.setVisibility(View.VISIBLE);
                    mSelectType = 1;
                    mModel.getTwoOrThreeLevelData(id);
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        mBinding.tlFragmentGoodsMainGoodsSelectTitle3.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                String cid;
                if (type == 0) {
                    mItemCid3 = mThree.get(tab.getPosition()).getId();
                    if (mGoodsType != null && mGoodsType.size() > 1) {
                        loadRecommendList(false);
                    }
                    cid = mItemCid3;
                    mRecommendValId = "";
                    mRecommendStr.clear();
                } else {
                    mCid3 = mThree.get(tab.getPosition()).getId();
                    loadAllList(false);
                    cid = mCid3;
                    mMaterValue.clear();
                    mStr.clear();
                }
                mBinding.rlGoodMatterChoose.setVisibility(View.VISIBLE);
                mBinding.rvGoodMatterChoose.setVisibility(View.VISIBLE);
                mModel.getMaterialBrand(cid);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        initFilterView();
        mModel.getAreaData(isRegionalConnection);
        mModel.getPriceSort();
        mModel.getAreaChoose();
        if (materialHomeFragment == null) {
            materialHomeFragment = (MaterialHomeFragment) getParentFragment();
        }

        mBinding.xrvFragmentGoodsMainGoodsList.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                loadAllList(false);
            }

            @Override
            public void onLoadMore() {
                if (type == 0) {
                    loadRecommendList(true);
                } else {
                    loadAllList(true);
                }
            }
        });

        mBinding.tvFragmentGoodsMainGoodsListSelect2.setOnClickListener(this);
        mBinding.tvFragmentGoodsMainGoodsListSelect1.setOnClickListener(this);
        mBinding.imgBackTop.setOnClickListener(this);
        mBinding.ivGoodsListSearch.setOnClickListener(this);
        mBinding.tvGoodsListScreen.setOnClickListener(this);
        LinearLayoutManager la = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false) {
            @Override
            public boolean canScrollHorizontally() {
                return false;
            }
        };
        mBinding.rvGoodMatterChoose.setLayoutManager(la);

        if (type == 0) {
            initRecommend();
        } else {
            initAll();
        }

    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onEvent(MaterialEvent event) {
        if (event.getMessageTag() == EventConstant.EVENT_MATERIAL_FILTER) {
            String text = (String) event.getMessageData();
            if (mModel.materialFilterJson != null && mModel.materialFilterJson.get() != null) {
                Objects.requireNonNull(Objects.requireNonNull(mModel.materialFilterJson.get())).setText(text);
            }
            loadAllList(false);
        } else if (event.getMessageTag() == EventConstant.EVENT_GOODS_LOC) {
            mLon = (String) event.getObject();
            mLat = (String) event.getMessageData();
            if (mModel.materialFilterJson != null && mModel.materialFilterJson.get() != null) {
                Objects.requireNonNull(Objects.requireNonNull(Objects.requireNonNull(Objects.requireNonNull(Objects.requireNonNull(Objects.requireNonNull(mModel.materialFilterJson.get())))))).setLat(mLat);
                Objects.requireNonNull(Objects.requireNonNull(Objects.requireNonNull(Objects.requireNonNull(Objects.requireNonNull(Objects.requireNonNull(mModel.materialFilterJson.get())))))).setLon(mLon);
            }
        } else if (event.getMessageTag() == EventConstant.EVENT_APPBAR_STATE_EXPANDED) {
            if (layoutParams != null) {
                isParentAppBarCollapsed = false;
            }
        } else if (event.getMessageTag() == EventConstant.EVENT_APPBAR_STATE_COLLAPSED) {
            if (layoutParams != null) {
                isParentAppBarCollapsed = true;
            }
        } else if (event.getMessageTag() == EventConstant.EVENT_APPBAR_STATE_COMMON) {
            if (layoutParams != null) {
                isParentAppBarCollapsed = false;
            }
        }
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventBus(MaterialEvent event) {
        if (event.getMessageTag() == EventConstant.EVENT_NEW_TAB_VALUE && !selfEmployedGoods && !isPromotionalGoods) {
            List<MenuEntity> menuList = (List<MenuEntity>) event.getMessageData();
            mPosition = "";
            industryPosition = (int) event.getObject();
            showMenuView(menuList);
        } else if (event.getMessageTag() == EventConstant.EVENT_REFRESH_FRAGMENT) {
            if (type == 0) {
                loadRecommendList(false);
            } else {
                loadAllList(false);
            }
        }
    }

    public void showMenuView(List<MenuEntity> data) {
        this.mGoodsType = data;
        mBinding.tlFragmentGoodsMainGoodsSelectTitle1.removeAllTabs();
        for (MenuEntity datum : data) {
            mBinding.tlFragmentGoodsMainGoodsSelectTitle1.addTab(mBinding.tlFragmentGoodsMainGoodsSelectTitle1.newTab().setText(datum.getName()));
        }

        for (int i = 0; i < data.size(); i++) {
            if (data.get(i).getId().equals(mPosition)) {
                mBinding.tlFragmentGoodsMainGoodsSelectTitle1.setScrollPosition(i, 0, true);
                mOneType = mPosition;
                if ("".equals(mPosition)) {
                    mBinding.tlFragmentGoodsMainGoodsSelectTitle1.postDelayed(() -> Objects.requireNonNull(Objects.requireNonNull(Objects.requireNonNull(Objects.requireNonNull(Objects.requireNonNull(mBinding.tlFragmentGoodsMainGoodsSelectTitle1.getTabAt(0)))))).select(), 100);
                }
            }
        }

        if (mOneType != null && !"".equals(mOneType)) {
            mCid1 = mOneType;
            mCategoryId = mTwoType;
            mCid3 = mThreeType;
            for (int i = 0; i < mGoodsType.size(); i++) {
                if (mGoodsType.get(i).getId().equals(mOneType)) {
                    int finalI = i;
                    mBinding.tlFragmentGoodsMainGoodsSelectTitle1.postDelayed(() -> Objects.requireNonNull(Objects.requireNonNull(Objects.requireNonNull(mBinding.tlFragmentGoodsMainGoodsSelectTitle1.getTabAt(finalI)))).select(), 100);
                }
            }
            mSelectTab = 1;
            mBinding.tvFragmentGoodsMainGoodsListSelect2.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 102 && data != null) {
            mLat = String.valueOf(data.getDoubleExtra(SelectAddressActivity.LATITUDE, 0));
            mLon = String.valueOf(data.getDoubleExtra(SelectAddressActivity.LONGTITUDE, 0));
            isRePositioning = true;
            loadAllList(false);
        }
    }


    public void locationClick() {
        Intent intent = new Intent();
        intent.setClass(requireContext(), SelectAddressActivity.class);
        intent.putExtra(SelectAddressActivity.TITLE, "选择定位地址");
        intent.putExtra(SelectAddressActivity.LATITUDE, Double.valueOf(mLat));
        intent.putExtra(SelectAddressActivity.LONGTITUDE, Double.valueOf(mLon));
        startActivityForResult(intent, 102);
    }

    private void initFilterView() {
        mThreeLevelPopWindow = new ThreeLevelAreaWindow(getContext()) {
            @Override
            protected void provinceClick(BaseAreaEntity baseAreaEntity, int position) {
                if (!mProvince.equals(baseAreaEntity.getId())) {
                    mCityId = "";
                }
                mProvince = baseAreaEntity.getId();
                mArea = baseAreaEntity.getSimpleName();
                if (mAreaId != null) {
                    mAreaId.clear();
                }
            }

            @Override
            protected void cityClick(BaseAreaEntity baseAreaEntity, int position) {
                if (!mCityId.equals(baseAreaEntity.getId())) {
                    if (mAreaId != null) {
                        mAreaId.clear();
                    }
                    mArea = "";
                }
                mCityId = baseAreaEntity.getId();
                mArea = baseAreaEntity.getSimpleName();
            }


            @Override
            protected void areaMoreClick(List list, int position) {
                if (mAreaId != null) {
                    mAreaId.clear();
                }
                mArea = "";
                for (Object o : list) {
                    BaseAreaEntity baseAreaEntity = (BaseAreaEntity) o;
                    if (mAreaId != null && !mAreaId.contains(baseAreaEntity.getId())) {
                        mAreaId.add(baseAreaEntity.getId());
                    }

                    if (!mArea.contains(baseAreaEntity.getSimpleName())) {
                        mArea = baseAreaEntity.getSimpleName();
                    }
                }
            }
        };
        mThreeLevelPopWindow.setShowSimpleName(true);
        mThreeLevelPopWindow.setBgView(mBinding.grayLayout);
        mThreeLevelPopWindow.setAreaMore();
        mThreeLevelPopWindow.setCitySingle();
        mThreeLevelPopWindow.setProvinceSingle();
        mThreeLevelPopWindow.setOnResultClick((key1, key2, key3) -> {
            if (type == 0) {
                if (mGoodsType != null && mGoodsType.size() > 1) {
                    loadRecommendList(false);
                }
            } else {
                loadAllList(false);
            }
        });
        mThreeLevelPopWindow.setOnDisMissClick(() -> {
            if (type == 0) {
                mBinding.rlGoodsMainGoodsListTab.setBackgroundResource(R.drawable.attestation_text_bg);
            }
            if ("".equals(mArea) || "不限".equals(mArea)) {
                mBinding.tvFragmentGoodsMainGoodsListSelect1.contentSelectRed(false, false);
            } else {
                mBinding.tvFragmentGoodsMainGoodsListSelect1.contentSelectRed(true, false);
            }
        });

        distanceWindow5 = new DictWindow5(getActivity(), 1);
        distanceWindow5.setBgView(mBinding.grayLayout);
        distanceWindow5.setCheckDefaultById("");
        if (type == 0) {
            distanceWindow5.setVisible(false);
        } else {
            distanceWindow5.setVisible(true);
        }
        distanceWindow5.setOnCallBack(dictEntity -> {
            mDistance = dictEntity.getId();
            mDistanceName = dictEntity.getName();
            mModel.materialFilterJson.get().setDistance(dictEntity.getName());
            mPopWindow.setDistanceDefault(distanceWindow5.getCheckDefultPosition(dictEntity.getId()), dictEntity.getId());
            if (type == 0) {
                if (mGoodsType != null && mGoodsType.size() > 1) {
                    loadRecommendList(false);
                }
            } else {
                loadAllList(false);
            }
        });
        distanceWindow5.setOnDisMissClick(() -> {
            if (type == 0) {
                mBinding.rlGoodsMainGoodsListTab.setBackgroundResource(R.drawable.attestation_text_bg);
            }
            if ("".equals(mDistanceName) || "不限".equals(mDistanceName)) {
                mBinding.tvFragmentGoodsMainGoodsListSelect2.contentSelectRed(false, false);
            } else {
                mBinding.tvFragmentGoodsMainGoodsListSelect2.contentSelectRed(true, false);
            }
        });

        mPopWindow = new MatterChooseMaterialFliterPopWindow3(getActivity());
        mPopWindow.setBgView(mBinding.grayLayout);
        mPopWindow.setFilterResultClick(new MatterChooseMaterialFliterPopWindow3.FilterResultClick() {
            @Override
            public void result(MaterialFilterJson materialFilterJson, List<DictEntity3> data, SparseBooleanArray checkBooleanArray) {
                mAreaId = materialFilterJson.getAreaList();
                mBrandId = materialFilterJson.getBrandId();
                mCategoryId = materialFilterJson.getCategoryId();
                mCid3 = materialFilterJson.getItemId();
                mMaterValue = materialFilterJson.getMaterValue();
                mDistance = materialFilterJson.getDistance();
                mPriceSort = String.valueOf(materialFilterJson.getPriceSort());
                loadAllList(false);

                distanceId = materialFilterJson.getDistance();
                distanceWindow5.setCheckDefaultById(distanceWindow5.getCheckDefultId(distanceId));

            }

            @Override
            public void queryTypeClassid(String id) {

            }

            @Override
            public void queryTypeChild(String id) {
                mModel.getTwoOrThreeLevelData(id);
                mSelectType = 1;
            }

            @Override
            public void queryNameChild(String id) {
                //品牌
                mModel.getFilterBrandModel(id);
                //sku属性
                mModel.getMaterialBrand(id);
            }
        });

        mPopWindow.setOnDisMissClick(() -> EventBus.getDefault().post(LeaseEvent.make().setMessageTag(EventConstant.EVENT_SHOP_VISIBLE)));
    }

    public void showBrandPopWindow(List<DictEntity3> data) {
        if (data == null || data.size() == 0) {
            return;
        }
        mPopWindow.setBrandData(data);
    }

    public void setDistanceData(List<DictEntity3> data) {
        this.mDistanceData = data;
        distanceWindow5.setData(data);
        mPopWindow.setDistanceData(data);
        distanceWindow5.setCheckDefaultById(mDistance);
        if (mSelectTab == 1) {
            EventBus.getDefault().post(new MaterialEvent().setMessageTag(EventConstant.EVENT_LOGISTICS_WINDOW_TOP));
            new Handler().postDelayed(() -> distanceWindow5.showPopwindow(mBinding.llFragmentGoodsMainGoodsListSelect, 0, -4), 300);
        }
    }

    public void setMaterialBrandData(List<MaterChooseEntity> data) {
        if (type == 0) {
            mRecommendMatterChooseAdapter.setDatas(data);
        } else {
            mMatterChooseAdapter.setDatas(data);
        }

        List<DictEntity3> list = new ArrayList<>();
        for (MaterChooseEntity datum : data) {
            List<DictEntity3> list1 = new ArrayList<>();
            for (MaterChooseEntity.TypeBean typeBean : datum.getType()) {
                list1.add(new DictEntity3(typeBean.getCid(), typeBean.getCname()));
            }
            list.add(new DictEntity3(datum.getId(), datum.getName(), list1));
        }
        mPopWindow.setSpecData(list);
    }

    public void setCurrentItem(String position, String threeId, String nameId, String fourId) {
        isStartAct1 = true;
        isStartAct2 = true;
        mOneType = position;
        mTwoType = threeId;
        mThreeType = fourId;
        for (int i = 0; i < mGoodsType.size(); i++) {
            if (mGoodsType.get(i).getId().equals(mOneType)) {
                int finalI = i;
                if (mBinding.tlFragmentGoodsMainGoodsSelectTitle1.getTabAt(finalI).isSelected()) {
                    setCurrentTab(mBinding.tlFragmentGoodsMainGoodsSelectTitle1.getTabAt(finalI));
                } else {
                    mBinding.tlFragmentGoodsMainGoodsSelectTitle1.postDelayed(() -> Objects.requireNonNull(mBinding.tlFragmentGoodsMainGoodsSelectTitle1.getTabAt(finalI)).select(), 100);
                }
            }
        }
        mSelectTab = 1;
        mBinding.tvFragmentGoodsMainGoodsListSelect2.setVisibility(View.VISIBLE);
    }

    public void setTwoOrThreeLevelData(List<TwoOrThreeLevelEntity> threeLevelData) {
        if (mSelectType == 0) {
            mBinding.tlFragmentGoodsMainGoodsSelectTitle2.removeAllTabs();
        } else {
            mBinding.tlFragmentGoodsMainGoodsSelectTitle3.removeAllTabs();
        }

        if (mSelectType == 0) {
            mTwo = threeLevelData;
            List<DictEntity3> data = new ArrayList<>();
            if (mSelectTab == 1) {
                for (int i = 0; i < threeLevelData.size(); i++) {
                    TwoOrThreeLevelEntity threeLevelDatum = threeLevelData.get(i);
                    mBinding.tlFragmentGoodsMainGoodsSelectTitle2.addTab(mBinding.tlFragmentGoodsMainGoodsSelectTitle2.newTab().setText(threeLevelDatum.getName()));
                    data.add(new DictEntity3(threeLevelDatum.getId(), threeLevelDatum.getName()));
                    if (!TextUtils.isEmpty(mTwoType)) {
                        if (threeLevelDatum.getId().equals(mTwoType) && isStartAct1) {
                            isStartAct1 = false;
                            int finalI = i;
                            mBinding.tlFragmentGoodsMainGoodsSelectTitle2.postDelayed(() -> mBinding.tlFragmentGoodsMainGoodsSelectTitle2.getTabAt(finalI).select(), 100);
                            mCategoryId = mTwoType;
                        }
                    }
                }
            } else {
                for (TwoOrThreeLevelEntity threeLevelDatum : threeLevelData) {
                    data.add(new DictEntity3(threeLevelDatum.getId(), threeLevelDatum.getName()));
                }

            }
            mPopWindow.setTypeData(data);
            if (threeLevelData.size() > 0) {
                if (mSelectTab == 1) {
                    mBinding.tlFragmentGoodsMainGoodsSelectTitle2.setVisibility(View.VISIBLE);
                    mBinding.ivFragmentGoodsMainGoodsTag2.setVisibility(View.VISIBLE);
                }
            } else {
                mBinding.tlFragmentGoodsMainGoodsSelectTitle2.setVisibility(View.GONE);
                mBinding.ivFragmentGoodsMainGoodsTag2.setVisibility(View.GONE);
            }
        } else {
            mThree = threeLevelData;
            List<DictEntity3> data = new ArrayList<>();
            if (mSelectTab == 1) {
                for (int i = 0; i < threeLevelData.size(); i++) {
                    TwoOrThreeLevelEntity threeLevelDatum = threeLevelData.get(i);
                    mBinding.tlFragmentGoodsMainGoodsSelectTitle3.addTab(mBinding.tlFragmentGoodsMainGoodsSelectTitle3.newTab().setText(threeLevelDatum.getName()));
                    data.add(new DictEntity3(threeLevelDatum.getId(), threeLevelDatum.getName()));
                    if (threeLevelDatum.getId().equals(mThreeType) && isStartAct2) {
                        isStartAct2 = false;
                        int finalI = i;
                        mBinding.tlFragmentGoodsMainGoodsSelectTitle3.postDelayed(() -> mBinding.tlFragmentGoodsMainGoodsSelectTitle3.getTabAt(finalI).select(), 100);
                        mModel.getMaterialBrand(mThreeType);
                        mCid3 = mThreeType;
                    }
                }
            } else {
                for (TwoOrThreeLevelEntity threeLevelDatum : threeLevelData) {
                    data.add(new DictEntity3(threeLevelDatum.getId(), threeLevelDatum.getName()));
                }
            }
            mPopWindow.setNameData(data);
            if (mThree != null && mThree.size() > 0) {
                mBinding.tlFragmentGoodsMainGoodsSelectTitle3.setVisibility(View.VISIBLE);
                mBinding.ivFragmentGoodsMainGoodsTag3.setVisibility(View.VISIBLE);
            } else {
                mBinding.tlFragmentGoodsMainGoodsSelectTitle3.setVisibility(View.GONE);
                mBinding.ivFragmentGoodsMainGoodsTag3.setVisibility(View.GONE);
            }
        }
    }

    @Override
    public void onMultiClick(View v) {
        switch (v.getId()) {
            case R.id.ll_self_employed:
                if (isZiYingChecked) {
                    mBinding.llSelfEmployed.setBackground(ContextCompat.getDrawable(requireActivity(), R.drawable.search_bg));
                    mBinding.btnZiying.setTextColor(ContextCompat.getColor(requireActivity(), R.color.color_333333));
                } else {
                    mBinding.llSelfEmployed.setBackground(ContextCompat.getDrawable(requireActivity(), R.drawable.search_new_blue_bg));
                    mBinding.btnZiying.setTextColor(ContextCompat.getColor(requireActivity(), R.color.color_main));
                }
                isZiYingChecked = !isZiYingChecked;
                if (type == 0) {
                    loadRecommendList(false);
                } else {
                    loadAllList(false);
                }
                break;
            case R.id.ll_promotional_goods:
                if (isPromotionChecked) {
                    mBinding.llPromotionalGoods.setBackground(ContextCompat.getDrawable(requireActivity(), R.drawable.search_bg));
                    mBinding.btnPromotionalGoods.setTextColor(ContextCompat.getColor(requireActivity(), R.color.color_333333));
                } else {
                    mBinding.llPromotionalGoods.setBackground(ContextCompat.getDrawable(requireActivity(), R.drawable.search_new_blue_bg));
                    mBinding.btnPromotionalGoods.setTextColor(ContextCompat.getColor(requireActivity(), R.color.color_main));
                }
                isPromotionChecked = !isPromotionChecked;
                if (type == 0) {
                    loadRecommendList(false);
                } else {
                    loadAllList(false);
                }
                break;
            case R.id.ll_sell_goods:
                if (isSellGoodGoodsChecked) {
                    mBinding.llSellGoods.setBackground(ContextCompat.getDrawable(requireActivity(), R.drawable.search_bg));
                    mBinding.btnSellGood.setTextColor(ContextCompat.getColor(requireActivity(), R.color.color_333333));
                } else {
                    mBinding.llSellGoods.setBackground(ContextCompat.getDrawable(requireActivity(), R.drawable.search_new_blue_bg));
                    mBinding.btnSellGood.setTextColor(ContextCompat.getColor(requireActivity(), R.color.color_main));
                }
                isSellGoodGoodsChecked = !isSellGoodGoodsChecked;
                if (type == 0) {
                    loadRecommendList(false);
                } else {
                    loadAllList(false);
                }
                break;
            case R.id.iv_goods_list_search:
                searchClick();
                break;
            default:
                break;
        }
    }

    private void loadRecommendList(boolean isLoadMore) {
        isLoadMoreRecommendGoodsList = isLoadMore;
        mRecommendPageNum = isLoadMore ? mRecommendPageNum + 1 : 1;
        StringBuilder stringBuilder = new StringBuilder();
        if (mAreaId != null && mAreaId.size() != 0) {
            for (String s : mAreaId) {
                stringBuilder.append(",").append(s);
            }
        }
        stringBuilder.replace(0, 1, "");
        Map<String, Object> map = new HashMap<>();
        map.put("province", mProvince);
        map.put("city", mCityId);
        map.put("area", stringBuilder.toString());
        map.put("page", mRecommendPageNum);
        map.put("limit", 10);
        map.put("valId", mRecommendValId);
        map.put("item_cid1", mItemCid1);
        map.put("item_cid2", mItemCid2);
        map.put("item_cid", mItemCid3);
        if (LocationUtil.isOpenLocation(getContext()) && LocationUtil.currentLocationIsValid()) {
            map.put("lon", String.valueOf(LocationUtil.getCurrentLongitude()));
            map.put("lat", String.valueOf(LocationUtil.getCurrentLatitude()));
        } else {
            map.put("lon", "0");
            map.put("lat", "0");
        }
        if (selfEmployedGoods) {
            map.put("selfSupportTag", 1);
            if (isPromotionChecked) {
                map.put("promoteStatus", 2);
            }
            if (isSellGoodGoodsChecked) {
                map.put("bestSellers", 1);
            } else {
                map.put("bestSellers", 0);
            }
            mModel.getSelfSupportMaterialsList(map);
        } else if (isPromotionalGoods) {
            if (isZiYingChecked) {
                map.put("selfSupportTag", 1);
            }
            mModel.getPromotionsList(map);
        } else {
            if (isZiYingChecked) {
                map.put("selfSupportTag", 1);
            }
            if (isPromotionChecked) {
                map.put("promoteStatus", 2);
            }
            mModel.getRecommendList(map);
        }
    }

    public void loadAllList(boolean isLoadMore) {
        isLoadMoreGoodsList = isLoadMore;
        mPageNum = isLoadMore ? mPageNum + 1 : 1;
        if ("7".equals(mCid1)) {
            Map<String, Object> map = new HashMap<>();
            map.put("pageNum", mPageNum);
            map.put("pageSize", 20);
            map.put("distance", mDistanceName);
            map.put("priceSort", mPriceSort);
            if (!"0".equals(mPriceSort)) {
                map.put("timeSort", "0");
            } else {
                map.put("timeSort", "2");
            }
            map.put("cid1", mCid1);
            map.put("cid3", mCid3);
            map.put("categoryId", mCategoryId);
            String mItemId = "";
            map.put("itemId", mItemId);
            map.put("brandId", mBrandId);
            map.put("materValue", mMaterValue);
            map.put("regionCode", mAreaId);
            map.put("areaId", mCityId);
            if (isZiYingChecked || selfEmployedGoods) {
                map.put("selfSupport", "1");
            }
            if (isPromotionalGoods || isPromotionChecked) {
                map.put("promoteStatus", 2);
            }
            if (isSellGoodGoodsChecked) {
                map.put("bestSellers", 1);
            } else {
                map.put("bestSellers", 0);
            }

            if (LocationUtil.isOpenLocation(getContext()) && LocationUtil.currentLocationIsValid()) {
                if (!isRePositioning) {
                    map.put("lon", String.valueOf(LocationUtil.getCurrentLongitude()));
                    map.put("lat", String.valueOf(LocationUtil.getCurrentLatitude()));
                } else {
                    map.put("lon", mLon);
                    map.put("lat", mLat);
                }
            } else {
                map.put("lon", "0");
                map.put("lat", "0");
            }
            mModel.getConcreteList(map, mProvince);
        } else {
            Map<String, Object> map = new HashMap<>();
            map.put("pageNum", mPageNum);
            map.put("pageSize", 20);
            map.put("distance", mDistanceName);
            map.put("priceSort", mPriceSort);
            if (!"0".equals(mPriceSort)) {
                map.put("timeSort", "0");
            } else {
                map.put("timeSort", "2");
            }
            map.put("cid1", mCid1);
            map.put("cid3", mCid3);
            map.put("categoryId", mCategoryId);
            String mItemId = "";
            map.put("itemId", mItemId);
            map.put("brandId", mBrandId);
            map.put("materValue", StringUtil.formatListToString(mMaterValue));
            map.put("regionCode", mAreaId);
            map.put("areaId", mCityId);
            if (isZiYingChecked || selfEmployedGoods) {
                map.put("selfSupportTag", 1);
            }
            if (isPromotionalGoods || isPromotionChecked) {
                map.put("promoteStatus", 2);
            }
            if (isSellGoodGoodsChecked) {
                map.put("bestSellers", 1);
            } else {
                map.put("bestSellers", 0);
            }
            if ("".equals(mCid1) && mIsFirst && whereJump == 0) {
                mIsFirst = false;
            } else {
                if (LocationUtil.isOpenLocation(getContext()) && LocationUtil.currentLocationIsValid()) {
                    if (!isRePositioning) {
                        map.put("lon", String.valueOf(LocationUtil.getCurrentLongitude()));
                        map.put("lat", String.valueOf(LocationUtil.getCurrentLatitude()));
                    } else {
                        map.put("lon", mLon);
                        map.put("lat", mLat);
                    }
                } else {
                    map.put("lon", "0");
                    map.put("lat", "0");
                }
                mModel.getGoodsList(map, mProvince);
            }
        }
    }

    public static void setMargins(View v, int l, int t, int r, int b) {
        if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
            p.setMargins(l, t, r, b);
            v.requestLayout();
        }
    }


    public void getConcreteList(List<ConcreteEntity> dataA) {
        List<GoodsListEntity> data = new ArrayList<>();
        for (ConcreteEntity concreteEntity : dataA) {
            data.add(new GoodsListEntity(true, "", concreteEntity.getDistance(), concreteEntity.getSelfSupportTag(), concreteEntity.getProviderName(), concreteEntity.getTitle(), 0, "", concreteEntity.getImage(), concreteEntity.getUnit(), concreteEntity.getCompanyNo()
                    , concreteEntity.getPrice(), "", concreteEntity.getId(), "", "", "", "", "", concreteEntity.getSort(), false, concreteEntity.getRanking(), concreteEntity.getStorageName(), concreteEntity.getLon(), concreteEntity.getLat(), concreteEntity.getLowestBuy(), concreteEntity.getImAccount()));
        }
        mBinding.xrvFragmentGoodsMainGoodsList.refreshComplete();
        if (isLoadMoreGoodsList) {
            if (data.size() > 0) {
                mBinding.xrvFragmentGoodsMainGoodsList.loadMoreComplete();
                mMaterialAdapter.addDatas(data);
            } else {
                mBinding.xrvFragmentGoodsMainGoodsList.setNoMore(true);
            }
            mBinding.xrvFragmentGoodsMainGoodsList.setVisibility(View.VISIBLE);
        } else {
            mBinding.xrvFragmentGoodsMainGoodsList.refreshComplete();
            if (data.size() > 0) {
                mBinding.xrvFragmentGoodsMainGoodsList.setVisibility(View.VISIBLE);
                mBinding.flContainer.setVisibility(View.GONE);
                mBinding.emptyView.setVisibility(View.GONE);
                mMaterialAdapter.setDatas(data);
                mBinding.xrvFragmentGoodsMainGoodsList.setLoadingMoreEnabled(true);
            } else {
                mMaterialAdapter.setDatas(null);
                mBinding.xrvFragmentGoodsMainGoodsList.setVisibility(View.GONE);
                mBinding.flContainer.setVisibility(View.VISIBLE);
                mBinding.emptyView.setVisibility(View.VISIBLE);
            }
        }
    }

    public void getRecommendList(List<RecommendListEntity> data) {
        if (isLoadMoreRecommendGoodsList) {
            if (null != data && data.size() > 0) {
                mBinding.xrvFragmentGoodsMainGoodsList.loadMoreComplete();
                mRecommendGoodsAdapter.addDatas(data);
            } else {
                mBinding.xrvFragmentGoodsMainGoodsList.setNoMore(true);
            }
            mBinding.xrvFragmentGoodsMainGoodsList.setVisibility(View.VISIBLE);
        } else {
            mBinding.xrvFragmentGoodsMainGoodsList.refreshComplete();
            if (null != data && data.size() > 0) {
                mBinding.xrvFragmentGoodsMainGoodsList.setVisibility(View.VISIBLE);
                mBinding.flContainer.setVisibility(View.GONE);
                mBinding.emptyView.setVisibility(View.GONE);
                mRecommendGoodsAdapter.setDatas(data);
                mBinding.xrvFragmentGoodsMainGoodsList.setLoadingMoreEnabled(true);
            } else {
                mRecommendGoodsAdapter.setDatas(null);
                mBinding.xrvFragmentGoodsMainGoodsList.setVisibility(View.GONE);
                mBinding.flContainer.setVisibility(View.VISIBLE);
                mBinding.emptyView.setVisibility(View.VISIBLE);
            }
        }
    }

    private void setTextViewBg(TextView textView, int bg, int img, int textColor) {
        Drawable drawable_n = ContextCompat.getDrawable(getContext(), img);
        drawable_n.setBounds(0, 0, drawable_n.getMinimumWidth(), drawable_n.getMinimumHeight());  //此为必须写的
        textView.setCompoundDrawables(null, null, drawable_n, null);
        textView.setTextColor(ContextCompat.getColor(getContext(), textColor));
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_fragment_goods_main_goods_list_select2:
                mBinding.tvFragmentGoodsMainGoodsListSelect2.contentSelectRed(false, true);
                if (type == 0) {
                    mModel.getFilterDistance(mItemCid1);
                    mBinding.rlGoodsMainGoodsListTab.setBackgroundResource(R.drawable.attestation_text_bg_2);
                } else {
                    mModel.getFilterDistance(mCid1);
                }
                break;
            case R.id.tv_fragment_goods_main_goods_list_select1:
                mBinding.tvFragmentGoodsMainGoodsListSelect1.contentSelectRed(false, true);
                EventBus.getDefault().post(new MaterialEvent().setMessageTag(EventConstant.EVENT_LOGISTICS_WINDOW_TOP));
                new Handler().postDelayed(() -> mThreeLevelPopWindow.showPopwindow(mBinding.llFragmentGoodsMainGoodsListSelect, 0, 0), 300);
                if (type == 0) {
                    mBinding.rlGoodsMainGoodsListTab.setBackgroundResource(R.drawable.attestation_text_bg_2);
                }
                break;
            case R.id.tv_goods_list_screen:
                EventBus.getDefault().post(LeaseEvent.make().setMessageTag(EventConstant.EVENT_SHOP_GONE));
                mSelectTab = 0;
                if (mTwo != null && mTwo.size() > 0) {
                    mPopWindow.setTypeDefault(mBinding.tlFragmentGoodsMainGoodsSelectTitle2.getSelectedTabPosition(), mCategoryId);
                } else {
                    mModel.getTwoOrThreeLevelData(mCid1);
                    mSelectType = 0;
                }

                if (mThree != null && mThree.size() > 0) {
                    mPopWindow.showListVisible(mBinding.tlFragmentGoodsMainGoodsSelectTitle3.getSelectedTabPosition());
                }

                if (mDistanceData != null && mDistanceData.size() > 0) {

                } else {
                    if (!"".equals(mCid1)) {
                        mModel.getFilterDistance(mCid1);
                    }
                }
                if (mAreaList.size() <= 0) {
                    mModel.getAreaData(isRegionalConnection);
                }
                mPopWindow.showPopwindowRight((GoodsAggregateActivity.getPopView()));
                break;
            case R.id.img_back_top:
                mBinding.xrvFragmentGoodsMainGoodsList.smoothScrollToPosition(0);
                break;
            default:
                break;
        }
    }

    @Deprecated
    public void getItemChoose(List<DictEntity3> data) {
        mPopWindow.setSpecData(data);
    }

    public void setAddressData
            (List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> data, String
                    areaCode) {
        this.mAreaList = data;
        mThreeLevelPopWindow.setData(data, true, areaCode);
    }

    public void showPriceSort(List<DictEntity3> list) {
        mPopWindow.setPriceData(list);
    }

    public void getAreaChoose(List<AreaChooseEntity> list) {
        List<DictEntity3> list1 = new ArrayList<>();
        for (AreaChooseEntity areaChooseEntity : list) {
            list1.add(new DictEntity3(areaChooseEntity.getId(), areaChooseEntity.getAreaName()));
        }
        mPopWindow.setAreaData(list1);
    }

    public void getGoodsList(List<GoodsListEntity> data) {
        mBinding.xrvFragmentGoodsMainGoodsList.refreshComplete();
        if (isLoadMoreGoodsList) {
            if (null != data && data.size() > 0) {
                mBinding.xrvFragmentGoodsMainGoodsList.loadMoreComplete();
                if (mMaterialAdapter != null) {
                    mMaterialAdapter.addDatas(data);
                }
            } else {
                mBinding.xrvFragmentGoodsMainGoodsList.setNoMore(true);
            }
            mBinding.xrvFragmentGoodsMainGoodsList.setVisibility(View.VISIBLE);
        } else {
            mBinding.xrvFragmentGoodsMainGoodsList.refreshComplete();
            if (null != data && data.size() > 0) {
                mBinding.xrvFragmentGoodsMainGoodsList.setVisibility(View.VISIBLE);
                mBinding.flContainer.setVisibility(View.GONE);
                mBinding.emptyView.setVisibility(View.GONE);
                if (mMaterialAdapter != null) {
                    mMaterialAdapter.setDatas(data);
                }
                mBinding.xrvFragmentGoodsMainGoodsList.setLoadingMoreEnabled(true);
            } else {
                if (mMaterialAdapter != null) {
                    mMaterialAdapter.setDatas(null);
                }
                mBinding.xrvFragmentGoodsMainGoodsList.setVisibility(View.GONE);
                mBinding.flContainer.setVisibility(View.VISIBLE);
                mBinding.emptyView.setVisibility(View.VISIBLE);
            }
        }
    }

    private void initRecommend() {
        sbl = new StringBuilder();
        for (MenuEntity menuEntity : mGoodsType) {
            mBinding.tlFragmentGoodsMainGoodsSelectTitle1.addTab(mBinding.tlFragmentGoodsMainGoodsSelectTitle1.newTab().setText(menuEntity.getName()));
            if (!"全部".equals(menuEntity.getName())) {
                sbl.append(",").append(menuEntity.getId());
            }
        }
        if (sbl.length() > 0) {
            sbl.replace(0, 1, "");
        }
        mBinding.xrvFragmentGoodsMainGoodsList.setLayoutManager(new GridLayoutManager(getContext(), 2));
        mRecommendGoodsAdapter = new RecommendGoodsAdapter(getContext(), null);
        mBinding.xrvFragmentGoodsMainGoodsList.setAdapter(mRecommendGoodsAdapter);
        initStickView();
        mRecommendGoodsAdapter.setmResembleGoodsClick(recommendListEntity -> {
            if (selfEmployedGoods) {
                materialHomeFragment.startForResemble(recommendListEntity.getCid1(), recommendListEntity.getCid2(), recommendListEntity.getCid(), 1);
            } else if (isPromotionalGoods) {
                materialHomeFragment.startForResemble(recommendListEntity.getCid1(), recommendListEntity.getCid2(), recommendListEntity.getCid(), 3);
            } else {
                materialHomeFragment.startForResemble(recommendListEntity.getCid1(), recommendListEntity.getCid2(), recommendListEntity.getCid(), 0);
            }
        });
        mRecommendGoodsAdapter.setOnItemClick(new AdapterOnItemClick<RecommendListEntity>() {
            @Override
            public void onItemClick(RecommendListEntity recommendListEntity, int position) {
                if ("7".equals(mGoodsType.get(mBinding.tlFragmentGoodsMainGoodsSelectTitle1.getSelectedTabPosition()).getId())) {
                    ConcreteDetailActivity2.start(getActivity(), recommendListEntity.getId());
                } else {
                    ShopGoodsDetailActivity.start(getContext(), recommendListEntity.getId(), "", recommendListEntity.getSkuid());
                }
            }
        });

        if (mGoodsType != null && mGoodsType.size() > 1) {

        } else {
            if (mRecommendGoodsAdapter != null) {
                mRecommendGoodsAdapter.setDatas(null);
            }
            mBinding.xrvFragmentGoodsMainGoodsList.setVisibility(View.GONE);
            mBinding.flContainer.setVisibility(View.VISIBLE);
            mBinding.emptyView.setVisibility(View.VISIBLE);
        }

        mBinding.xrvFragmentGoodsMainGoodsList.setPullRefreshEnabled(false);
        mBinding.xrvFragmentGoodsMainGoodsList.setOverScrollMode(View.OVER_SCROLL_NEVER);
        mRecommendMatterChooseAdapter = new RecommendMatterChooseAdapter(getContext(), null);
        mBinding.rvGoodMatterChoose.setAdapter(mRecommendMatterChooseAdapter);
        mRecommendMatterChooseAdapter.setmMatterChoose((entity, select) -> {
            select.contentSelectRed(false, true);
            StringBuilder mList = new StringBuilder();
            final String[] name = {""};
            MatterChooseWindow mNameWindow5 = new MatterChooseWindow(getContext());
            boolean isChange = false;

            mNameWindow5.setVisible(true);
            mNameWindow5.setOnCloseBack(() -> {
                select.contentSelectRed(!"全部".equals(name[0]), false);
            });

            if (type == 0) {
                mBinding.rlGoodsMainGoodsListTab.setBackgroundResource(R.drawable.attestation_text_bg_2);
            }

            mNameWindow5.setOnCallBack(dictEntity -> {
                mRecommendStr.put(entity.getName(), dictEntity);
                for (MaterChooseEntity.TypeBean value : mRecommendStr.values()) {
                    mList.append(",").append(value.getCid());
                }
                mList.replace(0, 1, "");
                name[0] = dictEntity.getCname();

                mRecommendValId = mList.toString();
                if (mGoodsType != null && mGoodsType.size() > 1) {
                    loadRecommendList(false);
                }
            });

            mNameWindow5.setOnDisMissClick(() -> mBinding.rlGoodsMainGoodsListTab.setBackgroundResource(R.drawable.attestation_text_bg));
            mNameWindow5.setData(entity.getType());
            mNameWindow5.setBgView(mBinding.grayLayout);
            for (String s : mRecommendStr.keySet()) {
                if (entity.getName().equals(s)) {
                    mNameWindow5.setCheckDefaultById(Objects.requireNonNull(Objects.requireNonNull(mRecommendStr.get(s))).getCid());
                    isChange = true;
                    break;
                } else {
                    isChange = false;
                }
            }
            if (!isChange) {
                mNameWindow5.setCheckDefaultById(entity.getType().get(0).getCid());
            }
            mNameWindow5.showPopwindow(mBinding.llFragmentGoodsMainGoodsListSelect, 0, 0);
        });
    }

    /****
     * 初始化置顶监听
     */
    private void initStickView() {
        mBinding.appBar.addOnOffsetChangedListener(new AppBarStateChangeListener() {
            @Override
            public void onStateChanged(AppBarLayout appBarLayout, State state) {
                if (state == State.EXPANDED) {
                    isAppBarExpended = true;
                } else {
                    isAppBarExpended = false;
                }
            }
        });

        mBinding.appBar.post(() -> {
            CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) mBinding.appBar.getLayoutParams();
            AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) layoutParams.getBehavior();
            int topAndBottomOffset = behavior.getTopAndBottomOffset();
            if (topAndBottomOffset != 0) {
                behavior.setTopAndBottomOffset(0);
                mBinding.appBar.setExpanded(true, true);
            }
        });

        final GridLayoutManager gridLayoutManager = (GridLayoutManager) mBinding.xrvFragmentGoodsMainGoodsList.getLayoutManager();

        mBinding.xrvFragmentGoodsMainGoodsList.addOnScrollListener(new RecyclerView.OnScrollListener() {
            //只在状态改变时调用
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                int completelyVisibleItemPosition = gridLayoutManager.findFirstCompletelyVisibleItemPosition();
                if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                    if (completelyVisibleItemPosition == 0) {
                        if (!isParentAppBarCollapsed) {
                            layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
                        } else {
                            if (isAppBarExpended) {
                                if (!isUpDragging) {//向下拖拽
                                    layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
                                } else { //向上拖拽
                                    layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
                                }
                            } else {
                                layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
                            }
                        }
                        mBinding.rlGoodsMainGoodsListTab.setLayoutParams(layoutParams);
                        mBinding.rlGoodsMainGoodsListTab.requestLayout();
                    } else {
                        if (isParentAppBarCollapsed && isAppBarExpended) {
                            if (isUpDragging) {
                                layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
                            } else {
                                layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
                            }
                            mBinding.rlGoodsMainGoodsListTab.setLayoutParams(layoutParams);
                            mBinding.rlGoodsMainGoodsListTab.requestLayout();
                        }
                    }
                }
            }

            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (dy > 0) {
                    if (isParentAppBarCollapsed) {
                        if (isAppBarExpended) {
                            if (isUpDragging) {
                                if (layoutParams.getScrollFlags() != FLAG_SCROLL_AND_ENTER_ALWAYS) {
                                    layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
                                    mBinding.rlGoodsMainGoodsListTab.setLayoutParams(layoutParams);
                                    mBinding.rlGoodsMainGoodsListTab.requestLayout();
                                } else {
                                    layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
                                    mBinding.rlGoodsMainGoodsListTab.setLayoutParams(layoutParams);
                                    mBinding.rlGoodsMainGoodsListTab.requestLayout();
                                }
                            } else {
                                if (layoutParams.getScrollFlags() != FLAG_NO_SCROLL) {
                                    layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
                                    mBinding.rlGoodsMainGoodsListTab.setLayoutParams(layoutParams);
                                    mBinding.rlGoodsMainGoodsListTab.requestLayout();
                                } else {
                                    layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
                                    mBinding.rlGoodsMainGoodsListTab.setLayoutParams(layoutParams);
                                    mBinding.rlGoodsMainGoodsListTab.requestLayout();
                                }
                            }
                        }
                    } else {
                        if (layoutParams.getScrollFlags() != FLAG_NO_SCROLL) {
                            layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
                            mBinding.rlGoodsMainGoodsListTab.setLayoutParams(layoutParams);
                            mBinding.rlGoodsMainGoodsListTab.requestLayout();
                        }
                    }
                    isUpDragging = true;
                } else if (dy < 0) {
                    if (isParentAppBarCollapsed) {
                        if (isAppBarExpended) {
                            if (!isUpDragging) {
                                if (layoutParams.getScrollFlags() != FLAG_NO_SCROLL) {
                                    layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
                                    mBinding.rlGoodsMainGoodsListTab.setLayoutParams(layoutParams);
                                    mBinding.rlGoodsMainGoodsListTab.requestLayout();
                                }
                            } else {
                                if (layoutParams.getScrollFlags() != FLAG_NO_SCROLL) {
                                    layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
                                } else {
                                    layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
                                }
                                mBinding.rlGoodsMainGoodsListTab.setLayoutParams(layoutParams);
                                mBinding.rlGoodsMainGoodsListTab.requestLayout();
                            }
                        }
                    } else {
                        if (layoutParams.getScrollFlags() != FLAG_NO_SCROLL) {
                            layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
                            mBinding.rlGoodsMainGoodsListTab.setLayoutParams(layoutParams);
                            mBinding.rlGoodsMainGoodsListTab.requestLayout();
                        }
                    }
                    isUpDragging = false;
                }
            }
        });
    }

    public void initAll() {
        mModel.getMenuModel("");
        if (mOneType != null && !"".equals(mOneType)) {

        } else {
            mBinding.tlFragmentGoodsMainGoodsSelectTitle1.setScrollPosition(0, 0, true);
            mBinding.tvFragmentGoodsMainGoodsListSelect2.setVisibility(View.GONE);
        }

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        mBinding.xrvFragmentGoodsMainGoodsList.setLayoutManager(linearLayoutManager);
        mMaterialAdapter = new MaterialAdapter(getContext(), null, false);
        mBinding.xrvFragmentGoodsMainGoodsList.setAdapter(mMaterialAdapter);
        mMaterialAdapter.setOnItemClick(new AdapterOnItemClick<GoodsListEntity>() {
            @Override
            public void onItemClick(GoodsListEntity goodsListEntity, int position) {
                if ("7".equals(mGoodsType.get(mBinding.tlFragmentGoodsMainGoodsSelectTitle1.getSelectedTabPosition()).getId())) {
                    MaterialFilterJson filterJson = new MaterialFilterJson();
                    filterJson.setStrengthId(goodsListEntity.getSort());
                    ConcreteDetailActivity2.start(getActivity(), goodsListEntity.getId(), filterJson);
                } else {
                    ShopGoodsDetailActivity.start(getContext(), goodsListEntity.getId(), "", goodsListEntity.getSkuid());
                }
            }
        });
        mBinding.xrvFragmentGoodsMainGoodsList.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
            }

            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (linearLayoutManager.findFirstVisibleItemPosition() > 1) {
                    mBinding.imgBackTop.setVisibility(View.VISIBLE);
                } else {
                    mBinding.imgBackTop.setVisibility(View.GONE);
                }
            }
        });

        mMatterChooseAdapter = new MatterChooseAdapter(getContext(), null);
        mBinding.rvGoodMatterChoose.setAdapter(mMatterChooseAdapter);
        mMatterChooseAdapter.setmMatterChoose((entity, select) -> {
            select.contentSelectRed(false, true);
            List<String> mList = new ArrayList<>();
            final String[] name = {""};
            boolean isChange = false;
            MatterChooseWindow mNameWindow5 = new MatterChooseWindow(getContext());

            mNameWindow5.setVisible(false);
            mNameWindow5.setOnCloseBack(() -> {
                if (!"".equals(name[0])) {
                    select.contentSelectRed(true, true);
                } else {
                    select.contentSelectRed(false, false);
                }
            });

            mNameWindow5.setOnCallBack(dictEntity -> {
                mStr.put(entity.getName(), dictEntity);
                for (MaterChooseEntity.TypeBean value : mStr.values()) {
                    if (!value.getCid().equals("")) {
                        mList.add(value.getCname());
                    }
                }

                name[0] = dictEntity.getCname();
                mMaterValue = mList;
                loadAllList(false);
            });

            mNameWindow5.setData(entity.getType());
            mNameWindow5.setBgView(mBinding.grayLayout);
            for (String s : mStr.keySet()) {
                if (entity.getName().equals(s)) {
                    mNameWindow5.setCheckDefaultById(mStr.get(s).getCid());
                    isChange = true;
                    break;
                } else {
                    isChange = false;
                }
            }

            if (!isChange) {
                mNameWindow5.setCheckDefaultById(entity.getType().get(0).getCid());
            }
            mNameWindow5.showPopwindow(mBinding.llFragmentGoodsMainGoodsListSelect, 0, 0);
        });

    }

    private void searchClick() {
        if (selfEmployedGoods) {
            HomeCategoryActivity.start(getActivity(), RequestCode.REQUEST_SHOP_SELFEMPLOYED);
        } else {
            HomeCategoryActivity.start(getActivity(), RequestCode.REQUEST_SHOP);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onEvent(ChooseAreaEvent event) {
        if (event.getMessageTag() == EventConstant.EVENT_CHOOSE_AERA && isRegionalConnection) {
            ProvinceEntity<List<ProvinceEntity>> list = (ProvinceEntity<List<ProvinceEntity>>) event.getMessageData();
            if (mThreeLevelPopWindow != null && this.mAreaList != null && list != null) {
                mThreeLevelPopWindow.setData(this.mAreaList, true, String.valueOf(list.getId()));
                mProvince = String.valueOf(list.getId());
                mCityId = "";
                if (mAreaId != null) {
                    mAreaId.clear();
                }
                loadRecommendList(false);
            }
        }
    }

    public String getCid1() {
        return sbl.toString();
    }

    public void setParentFragment(AppFragment appFragment) {
        if (appFragment instanceof MaterialHomeFragment) {
            materialHomeFragment = (MaterialHomeFragment) appFragment;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    private void setCurrentTab(TabLayout.Tab tab) {
        if (tab.getPosition() == 0) {
            mBinding.rlGoodMatterChoose.setVisibility(View.GONE);
            mBinding.rvGoodMatterChoose.setVisibility(View.GONE);
            if (type == 0) {
                mItemCid1 = "";
                mItemCid2 = "";
                mItemCid3 = "";
                mRecommendValId = "";
                mRecommendStr.clear();
            } else {
                mCid1 = "";
                mCid3 = "";
                mCategoryId = "";
                mMaterValue.clear();
                mStr.clear();
            }
            mDistance = "";
        }

        String cid;
        if (type == 0) {
            if (tab.getPosition() == 0) {
                //item_cid1这个字段需要传入每个子类得ID
                if (mGoodsType != null && mGoodsType.size() > 1) {
                    StringBuilder sbl = new StringBuilder();
                    for (MenuEntity menuEntity : mGoodsType) {
                        if (!"全部".equals(menuEntity.getName())) {
                            sbl.append(",").append(menuEntity.getId());
                        }
                    }
                    sbl.replace(0, 1, "");
                    if (industryPosition == 0) {
                        mItemCid1 = "";
                    } else {
                        mItemCid1 = sbl.toString();
                    }
                }
            } else {
                mItemCid1 = mGoodsType.get(tab.getPosition()).getId();
            }
            if (mGoodsType != null && mGoodsType.size() > 1) {
                loadRecommendList(false);
            } else {
                if (mRecommendGoodsAdapter != null) {
                    mRecommendGoodsAdapter.setDatas(null);
                }
                mBinding.xrvFragmentGoodsMainGoodsList.setVisibility(View.GONE);
                mBinding.flContainer.setVisibility(View.VISIBLE);
                mBinding.emptyView.setVisibility(View.VISIBLE);
            }
            cid = mItemCid1;
            mCid1 = mGoodsType.get(tab.getPosition()).getId();
        } else {
            mCid1 = mGoodsType.get(tab.getPosition()).getId();
            if (!TextUtils.isEmpty(mPosition) && mIsFirst) {
                mCid1 = mPosition;
                mIsFirst = false;
            }
            cid = mCid1;
        }

        if (type == 0) {
            loadRecommendList(false);
        } else {
            whereJump = -1;
            loadAllList(false);
        }
        if (tab.getPosition() == 0) {
            mBinding.tlFragmentGoodsMainGoodsSelectTitle2.setVisibility(View.GONE);
            mBinding.tvFragmentGoodsMainGoodsListSelect2.setVisibility(View.GONE);
            mBinding.ivFragmentGoodsMainGoodsTag2.setVisibility(View.GONE);
            mBinding.ivFragmentGoodsMainGoodsTag3.setVisibility(View.GONE);
        } else {
            mBinding.tlFragmentGoodsMainGoodsSelectTitle2.setVisibility(View.VISIBLE);
            mBinding.tvFragmentGoodsMainGoodsListSelect2.setVisibility(View.VISIBLE);
            mBinding.ivFragmentGoodsMainGoodsTag2.setVisibility(View.VISIBLE);
            mModel.getTwoOrThreeLevelData(cid);
        }
        mBinding.tlFragmentGoodsMainGoodsSelectTitle3.setVisibility(View.GONE);
        mBinding.ivFragmentGoodsMainGoodsTag3.setVisibility(View.GONE);

        mSelectType = 0;
        mSelectTab = 1;
    }
}
